﻿using soma.Models.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace soma.Services
{
    public class MessagesRepository : Repository
    {
        private static MessagesRepository instance = null;
        private const string MESSAGES_RESOURCES_DICTIONARY = "MessagesResourcesDictionary";

        protected override string CacheKeysResources
        {
            get
            {
                return MESSAGES_RESOURCES_DICTIONARY;
            }
        }

        public static MessagesRepository Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (locker)
                    {
                        if (instance == null)
                        {
                            instance = new MessagesRepository();
                        }
                    }
                }

                return instance;
            }
        }

        // Keep photos by tag and ordered most current date. Keep a maximum number of messages in cache.
        // If new messages are requested we make a request to get new photos that are more recent and remove some of the old ones
        // If the latest photo is more recent that X time we return that list
        private MessagesRepository()
        {
   //         lock (contextResourcesLocker)
            {
                context = HttpContext.Current;

                if (context != null)
                {
                    if (context.Cache[CacheKeysResources] == null)
                    {
                        context.Cache[CacheKeysResources] = new Dictionary<string, List<IResource>>();
                    }

                    if (context.Cache[CacheKeysTags] == null)
                    {
                        context.Cache[CacheKeysTags] = new Dictionary<string, List<string>>();
                    }
                }
            }
        }

        public List<MessageResource> GetMessages()
        {
            return null;
        }

        public List<MessageResource> GetMessagesByTag(string tag)
        {
            return null;
        }

    }
}